{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}{$column['column_name']} - 分类管理{/block}
<!-- CSS -->
{block name="css"}
{load href="/static/lib/treetable/jquery.treetable.css"}
{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">分类管理 <small>{$column['column_name']}</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            <li><a class="wscate-create" data-pid="0" data-path="0"> <i class="icon icon-plus"></i> 添加分类</a></li>
            <li><a href="{:url('/wscate/sort', $urlparam)}"> <i class="icon icon-sort"></i> 分类排序</a></li>
            <li><a href="{:url('/'.$column->module->module_path, $urlparam)}"><span class="text-danger"> <i class="icon icon-history"></i> {$column['column_name']}</span></a></li>
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" action="{:url('/wscate')}" method="get">
            <input type="hidden" name="siteid" value="{$siteid}">
            <input type="hidden" name="columnid" value="{$columnid}">
            <input type="text" name="keywords" class="form-control" placeholder="搜索">
            <button type="submit" class="btn btn-default">搜索</button>
            <button class="btn btn-primary btn-treetable" data-action="collapseAll" type="button">全部折叠</button>
        </form>
    </div>
</div>
<div class="panel">
    <table class="table table-condensed treetable">
        <thead>
            <tr>
                <th width="50" class="text-center"><input type="checkbox" id="selectBtn"></th>
                <th width="50">ID</th>
                <th>分类名称</th>
                <th>分类标题</th>
                <th width="80" class="text-center">首页</th>
                <th width="80" class="text-center">推荐</th>
                <th width="80" class="text-center">添加</th>
                <th width="80" class="text-center">修改</th>
                <th width="80" class="text-center">删除</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo"}
            <tr data-tt-id="{$vo['wscate_id']}" data-tt-parent-id="{$vo['wscate_pid']}" data-tt-branch="{$vo['wscate_child']?'true':''}">
                <td class="text-center"><input type="checkbox" name="wscateid[]" value="{$vo['wscate_id']}"></td>
                <td>{$vo['wscate_id']}</td>
                <td>{$vo['wscate_name']}</td>
                <td>{$vo['wscate_title']}</td>
                <td class="text-center">{$vo['wscate_home_html']|raw}</td>
                <td class="text-center">{$vo['wscate_recommend_html']|raw}</td>
                <td class="text-center"><a class="wscate-create" data-pid="{$vo['wscate_id']}" data-path="{$vo['wscate_path'].','.$vo['wscate_id']}">添加</a></td>
                <td class="text-center"><a href="{:url('/wscate/edit', $urlparam.'&id='.$vo['wscate_id'])}">修改</a></td>
                <td class="text-center"><a class="delete" data-url="{:url('/wscate/delete','siteid='.$siteid.'&columnid='.$columnid.'&id='.$vo['wscate_id'])}">删除</a></td>
            </tr>
            {/volist}
        </tbody>
    </table>
    {empty name="list"}
    <div class="mb20 mt20 text-center">
        {if ($keywords!='')}
        未搜索到 “{$keywords}” 相关的分类 &nbsp; <a href="{:url('/wscate', $urlparam)}">查看全部分类</a>
        {else /}
        暂未添加分类
        {/if}
    </div>
    {/empty}
    {notempty name="list"}
    <div class="mb10 ml10 mt10">
        <button class="btn btn-danger wscate-delete" type="button" data-url="{:url('/wscate/delete')}">删除分类</button>
        <div class="btn-group dropup">
            <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown">
                设置属性 <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a class="wscate-attr" data-attr="home" data-value="1">首页内容</a></li>
                <li><a class="wscate-attr" data-attr="home" data-value="0">取消首页</a></li>
                <li class="divider"></li>
                <li><a class="wscate-attr" data-attr="recommend" data-value="1">推荐内容</a></li>
                <li><a class="wscate-attr" data-attr="recommend" data-value="0">取消推荐</a></li>
            </ul>
        </div>
        <button class="btn btn-primary btn-treetable" data-action="collapseAll" type="button">全部折叠</button>
    </div>
    {/notempty}
</div>
{/block}
<!-- JS -->
{block name="js"}
{load href="/static/lib/treetable/jquery.treetable.js"}
{/block}
{block name="jscode"}
<script type="text/javascript">
$(document).ready(function() {
    $(".wscate-create").click(function(e) {
        var data = {
            'wscate_siteid': {$siteid},
            'wscate_columnid': {$columnid},
            'wscate_pid': $(this).data('pid'),
            'wscate_path': $(this).data('path')
        };
        var url = "{:url('/wscate/save')}";
        bootbox.prompt("分类名称", function(result) {
            if (result != null) {
                if (result == '') return sxj.msg_error('提示：名称必须填写!');
                data.wscate_name = result;
                sxj.ajax_post(url, data);
                return false;
            }
        });
    });

    $(".wscate-attr").click(function(event) {
        var attr = $(this).data('attr');
        var value = $(this).data('value');
        var chk = chk_all();
        var url = "{:url('/wscate/attr')}";
        sxj.ajax_put(url, { id: chk.join(','), attr: attr, value: value });
    });

    /*删除分类*/
    $(".wscate-delete").click(function(event) {
        var url = $(this).data('url');
        var checksStatus = chk_all();
        url = url + '?siteid={$siteid}';
        url = url + '&columnid={$columnid}';
        url = url + '&id=' + checksStatus.join(',');
        if (checksStatus != false) {
            bootbox.confirm({
                message: "确定要删除选中的内容？",
                callback: function(result) {
                    if (result) {
                        sxj.ajax_del(url);
                    }
                }
            });
        }
    });

    /**/
    $("#selectBtn").click(function() {
        $("input[name='wscateid[]']").prop("checked", this.checked);
    });

    var chk_all = function() {
        var ids = $("input[name='wscateid[]']:checked"),
            chk_ids = new Array();
        if (ids.length == 0) {
            return sxj.msg_error('提示：未选择内容！');
        }
        ids.each(function(index, el) {
            chk_ids.push(el.value);
        });
        return chk_ids;
    }
});
</script>
{/block}